#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int p1[N],p2[N];
int n,m1,m2;

int find1(int x)
{
    if (p1[x] != x) p1[x] = find1(p1[x]);
    return p1[x];
}
int find2(int x)
{
    if (p2[x] != x) p2[x] = find2(p2[x]);
    return p2[x];
}

void solve()
{
	cin>>n>>m1>>m2;
	for(int i=1;i<=n;i++) p1[i]=i,p2[i]=i;

	for(int i=1;i<=m1;i++)
	{
		int a,b;
		cin>>a>>b;
		p1[find1(a)] = find1(b);
	}

	for(int i=1;i<=m2;i++)
	{
		int a,b;
		cin>>a>>b;
		p2[find2(a)] = find2(b);
	}

	vector<pair<int,int>> ans;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int x=find1(i);
			int y=find1(j);
			int x1=find2(j);
			int y1=find2(i);
			if(x!=y&&x1!=y1)
			{
				ans.push_back({i,j});
				p1[find1(i)] = find1(j);
				p2[find2(i)] = find2(j);
			}
		}
	}

	cout<<ans.size()<<'\n';
	for(auto[k,v]:ans) cout<<k<<" "<<v<<'\n';
	
}

int main()
{
	close();
	// int T; cin>>T;
	// while (T--) solve();
	solve();
	return 0;
}
//A有n个节点,初始有m1个边
//B有n个节点,初始有m2个边
//往A中连边的同时(不成环),也要同时往B中连同样两节点的边(且B中也要不成环),问答案最多能连多少条边
//题目的意思是两条边就会形成环